package com.imooc.diners.controller;

import com.imooc.commons.model.domain.ResultInfo;
import com.imooc.commons.model.vo.NearMeDinerVO;
import com.imooc.commons.utils.ResultInfoUtil;
import com.imooc.diners.service.NearMeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author gcq
 * @Create 2022-12-12
 */
@RestController
@RequestMapping("nearme")
public class NearController {

    @Autowired
    private NearMeService nearMeService;
    @Autowired
    private HttpServletRequest servletRequest;

    /**
     * 更新用户地址
     *
     * @param access_token
     * @param lng
     * @param lat
     * @return
     */
    @PostMapping
    public ResultInfo updateDinerLocation(String access_token,
                                          @RequestParam Float lng,
                                          @RequestParam Float lat) {
        nearMeService.updateDinerLocation(access_token, lng, lat);
        return ResultInfoUtil.buildSuccess(servletRequest.getServletPath());
    }

    /**
     * 获取附近的人
     *
     * @param access_token 用户 accessToken
     * @param radius       半径
     * @param lng          经度
     * @param lat          维度
     * @return
     */
    @GetMapping
    public ResultInfo nearMe(String access_token,
                             Integer radius,
                             Float lng, Float lat) {
        List<NearMeDinerVO> nearMe = nearMeService.findNearMe(access_token, radius, lng, lat);
        return ResultInfoUtil.buildSuccess(servletRequest.getServletPath(), nearMe);
    }
}